package com.zhiliang.waibao.myapplication.utils;

/**
 * Created by Administrator on 2018/4/26.
 */

public class FalseClickListener {
    public static final int MIN_CLICK_DELAY_TIME = 5000;
    private static long lastClickTime;
    private static int lastButtonId = -1;
    public static boolean isFastDoubleClick() {
        long time = System.currentTimeMillis();
        long timeD = time - lastClickTime;
        if (0 < timeD && timeD < MIN_CLICK_DELAY_TIME) {
            return true;
        }
        lastClickTime = time;
        return false;
    }


    /**
     * 判断两次点击的间隔，如果小于10000，则认为是多次无效点击
     *
     * @return
     */
    public static boolean isFastClick() {
        return isFastDoubleClick(-1, MIN_CLICK_DELAY_TIME);
    }

    /**
     * 判断两次点击的间隔，如果小于1000，则认为是多次无效点击
     *
     * @return
     */
    public static boolean isFastDoubleClick(int buttonId) {
        return isFastDoubleClick(buttonId, MIN_CLICK_DELAY_TIME);
    }

    /**
     * 判断两次点击的间隔，如果小于diff，则认为是多次无效点击
     *
     * @param diff
     * @return
     */
    public static boolean isFastDoubleClick(int buttonId, long diff) {
        long time = System.currentTimeMillis();
        long timeD = time - lastClickTime;
        if (lastButtonId == buttonId && lastClickTime > 0 && timeD < diff) {
            return true;
        }
        lastClickTime = time;
        lastButtonId = buttonId;
        return false;
    }

}


